home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / diskutil / backup.arc / BKUPSEL.C < prev    next >
C/C++ Source or Header  |  1986-01-04  |  11KB  |  374 lines

  1. /* public domain; all rights reserved by: Robert F. Ritter (c) 1986 */
  2. #include "osbind.h"
  3.  
  4.  
  5.  
  6. #define ARC "\\bin\\arc"  /* where is your arc situated? */
  7.  
  8.  
  9. struct dta {
  10.                 char  reserved[21];
  11.                 char  fab;
  12.                 unsigned time;
  13.                 unsigned date;
  14.                 long  size;
  15.                 char  name[];
  16.            };
  17.  
  18. struct dta *dta_ptr;
  19.  
  20. unsigned sys_time, sys_date;
  21.  
  22. int     contrl[ 12 ],
  23.         intin[ 256 ], ptsin[ 256 ],
  24.         intout[ 256 ], ptsout[ 256 ],
  25.         workin[]={ 1,1,1,1,1,1,1,1,1,1,2 }, workout[ 57 ],
  26.         handle,
  27.         i, j,
  28.         x, y, w, h,
  29.         xdial, ydial, wdial, hdial,
  30.         k = 0,
  31.         file_handle, myfile, oldfile,
  32.         button,
  33.         ret;
  34.  
  35. long    space,
  36.         box_adr;
  37.  
  38. char    path[50],
  39.         volume[50],
  40.         name[50],
  41.         drive[3],
  42.         crlf[2],
  43.         today[10],
  44.         totime[10],
  45.         realdta[44],
  46.         out_filename[12],
  47.         disk_no[4];
  48.  
  49. long strlen(string)
  50.   char *string;
  51.   {
  52.         char *string_pointer = string;
  53.  
  54.         while ( *string_pointer )
  55.            ++string_pointer;
  56.  
  57.         return ((long) string_pointer - string );
  58.  
  59.   }
  60.  
  61. char * strcat(s, t)
  62.   char s[], t[];
  63. {
  64.         int i, j;
  65.         i = j = 0;
  66.         while(s[i] != '\0')          /* find end of s */
  67.            i++;
  68.         while((s[i++] = t[j++]) != '\0');   /* copy t */
  69. }
  70.  
  71. char strcpy(s, t)
  72.   char *s, *t;
  73. {
  74.         while(*s++ = *t++);
  75. }
  76.  
  77. strequ ( str1, str2 )
  78.   char str1[], str2[];
  79.     {
  80.         int i = 0, answer;
  81.         while( str1[i] == str2[i] && str1[i] != '\0'
  82.                                   && str2[i] != '\0' )
  83.           ++i;
  84.         if( str1[i] == '\0' && str2[i] == '\0' )
  85.           answer = 1;
  86.         else
  87.           answer = 0;
  88.         return( answer );
  89.     }
  90.  
  91. itoa (n, s)
  92.   char s[];
  93.   int n;
  94.     {
  95.         int i;
  96.         i = 2;
  97.         strcpy(s, "000");
  98.         do {
  99.             s[i--] = (n % 10) + '0';
  100.             } while ((n /= 10) > 0);
  101.     }
  102.  
  103. ltoa (n, s)
  104.   char s[10];
  105.   long n;
  106.     {
  107.         long n2;
  108.         int i;
  109.         n2 = n;
  110.         i = 9;
  111.         do {
  112.             s[i--] = n2 - ((n2 / 10) * 10) + '0';
  113.             } while ((n2 /= 10) > 0);
  114.     }
  115.  
  116. itodate (idate, date)
  117.   unsigned idate;
  118.   char date[10];
  119.   {
  120.         unsigned yy, mm, dd;
  121.  
  122.         yy = (idate >> 9 & 0x7F) + 80;
  123.         mm = idate >> 5 & 0xF;
  124.         dd = idate & 0x1F;
  125.  
  126.         date[0] = (dd/10) + '\060';
  127.         date[1] = (dd%10) + '\060';
  128.         date[2] = '/';
  129.         date[3] = (mm/10) + '\060';
  130.         date[4] = (mm%10) + '\060';
  131.         date[5] = '/';
  132.         date[6] = (yy/10) + '\060';
  133.         date[7] = (yy%10) + '\060';
  134.   }
  135.  
  136. itotime (itime, time)
  137.    unsigned itime;
  138.    char time[10];
  139.   {
  140.         unsigned hrs, mins, secs;
  141.  
  142.         hrs = itime >> 11 & 0x1F;
  143.         mins = itime >> 5 & 0x3F;
  144.         secs = (itime & 0x1F) << 1;
  145.  
  146.         time[0] = (hrs/10) + '\060';
  147.         time[1] = (hrs%10) + '\060';
  148.         time[2] = ':';
  149.         time[3] = (mins/10) + '\060';
  150.         time[4] = (mins%10) + '\060';
  151.         time[5] = ':';
  152.         time[6] = (secs/10) + '\060';
  153.         time[7] = (secs%10) + '\060';
  154.   }
  155.  
  156. int stoi(string)
  157. char string[];
  158. {
  159.         int i, int_val, result=0;
  160.         for (i=0; string[i] >= '0' && string[i] <= '9'; ++i){
  161.                 int_val = string[i] - '0';
  162.                 result = result * 10 + int_val;
  163.         }
  164.         return(result);
  165. }
  166.  
  167.  
  168. /*************************************************/
  169. main(argc, argv)
  170. char **argv;
  171. int    argc;
  172.    {
  173.         int x;
  174.         int i, j, k;
  175.         char  cc[20], xx[20];
  176.         unsigned hrs=0, mins=0, secs=0, yy=80, mm=0, dd=0;
  177.         int counter;
  178.  
  179.     crlf[0] = 0x0d;
  180.     crlf[1] = 0x0a;
  181.  
  182.     oldfile = Fopen( "bkuptime", 0);
  183.     myfile = Fcreate("newtime", 0);
  184.  
  185.     if (argc < 2) {
  186.         Fwrite(0, 41L, "usage: BKUPSEL path <dd/mm/yy> <hh:mm:ss>");
  187.         Fwrite(0, 2L, crlf);
  188.         exit(-1);
  189.         }
  190.     else {
  191.     strcpy(cc, "00/00/80");
  192.         if (argc >= 3)
  193.            strcpy(cc, argv[2]); /* the date to select by */
  194.         else Fread(oldfile, 10L, cc);
  195.  
  196.         Fwrite(0, 38L, "Preparing backup list of files since: ");
  197.         Fwrite(0, 8L, cc);
  198.         Fwrite(0, 2L, "  ");
  199.  
  200.         i = strlen(cc);
  201.  
  202.         counter = 0;
  203.         k = 0;
  204.         for (j=0; j<=i;++j){
  205.                 if (cc[j] >= '0' && cc[j] <= '9'){
  206.                         xx[k] = cc[j];
  207.                         ++k;
  208.                         }
  209.                 else {
  210.                         xx[k] = '\0';
  211.                         x = stoi(xx);
  212.                         k = 0;
  213.                         ++counter;
  214.                         switch(counter){
  215.                            case 1:
  216.                                 if (x <= 31 && x > 0) dd = x;
  217.                                 break;
  218.                            case 2:
  219.                                 if (x <= 12 && x > 0) mm = x;
  220.                                 break;
  221.                            case 3:
  222.                                 if (x >= 80) yy = x;
  223.                                 break;
  224.                            } /* switch */
  225.                         } /* else */
  226.                 } /* for */
  227.  
  228.     strcpy(cc, "00:00:00");
  229.         if (argc >= 4)
  230.            strcpy(cc, argv[3]); /* the time to select by */
  231.         else Fread(oldfile, 8L, cc);
  232.  
  233.         Fwrite(0, 8L, cc);
  234.  
  235.         i = strlen(cc);
  236.  
  237.         counter = 0;
  238.         k = 0;
  239.         for (j=0; j<=i; j++){
  240.                 if (cc[j] >= '0' && cc[j] <= '9'){
  241.                         xx[k] = cc[j];
  242.                         ++k;
  243.                         }
  244.                 else {
  245.                         xx[k] = '\0';
  246.                         x = stoi(xx);
  247.                         k = 0;
  248.                         ++counter;
  249.                         switch(counter){
  250.                            case 1:
  251.                                 if (i!= 0 && x <= 23 && x >= 0) hrs=x;
  252.                                 break;
  253.                            case 2:
  254.                                 if (x <= 59 && x >= 0) mins = x;
  255.                                 break;
  256.                            case 3:
  257.                                 if (x <= 59 && x >= 0) secs = x;
  258.                                 break;
  259.                            }
  260.                         }
  261.                 }
  262.         sys_time = (hrs << 11) + (mins << 5) + (secs >> 1);
  263.         sys_date = ((yy - 80) << 9) + (mm << 5) + dd;
  264.  
  265.         strcpy(out_filename, "thisbkup.sh");
  266.         file_handle = Fcreate(out_filename, 0);
  267.  
  268.         dta_ptr = (struct dta *) realdta;
  269.         Fsetdta(dta_ptr);
  270.  
  271.         Fwrite(0, 2L, crlf);
  272.  
  273.         strcpy( drive, argv[1]);
  274.         read_the_directory();
  275.  
  276.         sys_time = Tgettime();
  277.         sys_date = Tgetdate();
  278.         itotime(sys_time, totime);
  279.         itodate(sys_date, today);
  280.         Fwrite(myfile, 8L, today);
  281.         Fwrite(myfile, 2L, crlf);
  282.         Fwrite(myfile, 8L, totime);
  283.         Fwrite(myfile, 2L, crlf);
  284.         }
  285.    }
  286. /*************************************************/
  287.  
  288.  
  289. /*************************************************/
  290. read_the_directory()
  291.    {
  292.      char thispath[50], cur_dir[50], charspace[10], totals[50];
  293.         strcpy(path, drive);
  294.         strcpy( thispath, path );
  295.         strcat( thispath, "\\*.*" );
  296.         ret = Fsfirst(thispath,0x10); /* get the first item on the volume   */
  297.         while (ret == 0)
  298.           {
  299.             if (dta_ptr->fab == 0x10)               /* found a directory     */
  300.                {if (   (!strequ( dta_ptr->name, "." ))
  301.                     && (!strequ( dta_ptr->name, ".." )) )
  302.                  {
  303.                    strcpy(cur_dir,dta_ptr->name);
  304.                    d